﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/WEB-INF/view/include/jQgrid.jsp"%>

</head>
<body>
<%-- <s:lacksPermission name="user:view">
   <jsp:forward page="/error/403" />
</s:lacksPermission>  --%>
	<div class="container-fluid" id="main-container">
		<div id="page-content" class="clearfix">
			<div class="row-fluid">
				<div class="row-fluid">
					<!-- 检索  -->
					 <div class="ibox-title" style="border-color: white;">
						 <div class="row">
                            <div class="col-sm-12 ">
                                <div class="form-group form-inline">
                                <span>类型：</span>
                                   <select class="form-control" style="width:150px;" id="type">
                                    <option value="">请选择</option>
                                    <c:forEach items="${dictionarydatas }" var="dicts">
                                    <option value="${dicts.type }">${dicts.type }</option>
                                    </c:forEach>
                                    </select>
                                    <span>描述：</span>
                                    <input id="description" type="text" placeholder="请输入描述" class="form-control">
                                        <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a>
                                </div>
                            </div>
                        </div>
					</div>
					<!-- biaogebigin -->
					<div class="ibox-content" style=" padding-left: 0px;">
						<div class="jqGrid_wrapper">
							<table id="table_list"></table>
							<div id="pager_list"></div>
						</div>
					</div>
					<!-- tableover -->
				</div>
				<!-- PAGE CONTENT ENDS HERE -->
				
			</div>
			<!--/row-->
		</div>
		<!--/#page-content-->
	</div>
	<!--/.fluid-container#main-container-->


	<script type="text/javascript">
		$(top.hangge());
		$(function(){
			$.jgrid.defaults.styleUI = "Bootstrap";
			$("#table_list").jqGrid({
				url: '<%=contextPath %>/dictionarydata/listData',
				data : {},
				datatype : "json",
				autowidth : true,
				shrinkToFit : true,
				mtype : "post",
				sortname:"type", //设置默认的排序列
				sortorder:"desc",
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				colNames : ["id", "键值","类型", "标签","描述", "是否可编辑","操作"],
				colModel : [{
					name : "id",
					index : "id",
					hidden:true
				}, {
					name : "value",
					index : "value",
					width : 50
				}, {
					name : "type",
					index : "type",
					width : 90
				}, {
					name : "valueName",
					index : "valueName",
					width : 50
				}, {
					name : "description",
					index : "description",
					width : 50
				},{
					name : "isfixed",
					index : "isfixed",
					width : 80,
					formatter:function(cellvalue, options, row){
						if(cellvalue==0){
					         return "是";
					    }
						if(cellvalue==1){
					         return "否";
					    }
					}
				},{
					formatter:function(cellvalue, options, row){
						if(row.isfixed==0){
							   return  " <s:hasPermission name="dictionarydata:update"><a class='btn btn-mini btn-info' title='修改' onclick='showedit("+row.id+")'><i class='icon-edit'></i></a></s:hasPermission> "
							   +" <s:hasPermission name="dictionarydata:add"><a class='btn btn-mini btn-danger' title='添加键值' onclick='showaddvalue("+row.id+")'><i class='icon-plus'></i></a></s:hasPermission> "
							   +" <s:hasPermission name="dictionarydata:delete"><a class='btn btn-mini btn-danger' title='删除' onclick='del("+row.id+")'><i class='icon-trash'></i></a></s:hasPermission> ";
						}else{
							return "";
						}
					},
					width : 100
				} ],
				height : $(window).height() - 170,
				pager : "#pager_list",
				multiselect: true,//多选按钮
				//multiboxonly: true,
				viewrecords : true,
				hidegrid : false,
				
			});
			
			//表格自适应高宽
			$(window).bind("resize", function() {
				var b = $(".jqGrid_wrapper").width();
				$("#table_list").setGridWidth(b);
				$("#table_list").setGridHeight($(window).height() - 170);
			})
				$("#table_list").navGrid('#pager_list',{edit:false,add:false,del:false,search:false})
				/* 判断是否有添加权限 */
				<s:hasPermission name="dictionarydata:add">
				$("#table_list").navButtonAdd('#pager_list',{   
					   caption:"",    
					   buttonicon:"glyphicon glyphicon-plus", 
					   onClickButton: function(){ 
						   openyem("添加字典","<%=contextPath %>/dictionarydata/addView",400,350);//打开页面
					   }, 
					   position:"first"  
					});
				</s:hasPermission>
			//检索
			$("#find_btn").click(function(){ 
				var type = $("#type").val();
		        var description = $("#description").val(); 
		        $("#table_list").jqGrid('setGridParam',{ 
		            postData:{'type':type,'name':description}, //发送数据 
		            page:1 
		        }).trigger("reloadGrid"); //重新载入 
		    }); 
		});
		
		//删除
		function del(id){
			swalopen(id,"<%=contextPath %>/dictionarydata/delete");
		};
		//修改
		function showedit(id){
			openyem("修改字典","<%=contextPath %>/dictionarydata/showedit?id="+id,400,350);
		}
		//添加键值
		function showaddvalue(id){
			openyem("添加键值","<%=contextPath %>/dictionarydata/addValueView?id="+id,400,350);
		}
  </script>

</body>
</html>

